function record = SinkToFile(varargin)
% SINKTOFILE Constructor function
% SYNTAX:
%   SinkToFile()
%   SinkToFile(record)
%   SinkToFile(filename,repeat)

switch nargin
    case 0
        % SinkToFile()
        record.time = [];
        record.mean = [];
        record.var  = [];
        record.repeat = 0;
        record.VariableName = '';
        record.VariableUnit = '';        
        record = class(record,'SinkToFile');
    case 1
        % SinkToFIle(record)
        if(isa(varargin{1},'SinkToFile'))
            record = varargin{1};
        else
            error('Wrong argument type');
        end
    case 2
        % SinkToFile(filename,repeat)
        filename = varargin{1};
        repeat = varargin{2};
        fid = fopen(filename);
        if(fid<0)% open failed
            error('Failed to open %s\n',filename);
        end
        formatstring = '%f %f %f';
        data = textscan(fid,formatstring);
        record.time = data{1};
        record.mean = data{2};
        record.var  = data{3};
        record.repeat = repeat;
        record.VariableName = '';
        record.VariableUnit = '';          
        fclose(fid);
        record = class(record,'SinkToFile');
    otherwise
        error('Wrong number of input arguments');
end
